#ifndef _TASK_H_
#define _TASK_H_

#include <future>
#include <QMainWindow>
#include <QDebug>
#include <QDockWidget>
#include <QLayout>
#include <QThread>
#include <mutex>
#include <direct.h>

#include "Json.h"
#include "singleton.h"
#include "lv_api.h"
#include "dockWidget.h"
#include "show2D.h"
#include "show3D.h"

class Task : public QWidget
{
    Q_OBJECT

public:
    enum WindowType
    {
        IR = 0,
        Depth,
        CloudPoint,
    };

    enum RenderType
    {
        R_IR                = (0x01),
        R_Depth             = (0x01 << 1),
        R_CloudPoint        = (0x01 << 2),
    };

public:
    Task(QMainWindow * mainWindow, QWidget * widgetForDepth, QWidget * widgetForIR, QWidget * widgetForCloudPoint);
    ~Task();

    void start();

    void stop();

    void work();

    void workForTigger();

    void showWindow(QWidget* obj, bool setShow = true);

    void __render(uint8_t type);

    void setBlackBG(bool src) {reinterpret_cast<Show2D*>(m_Depth)->setBlackBG(src);}

    bool setlock(bool isLock);

    void setFullScreen(bool isFull)
    {
        reinterpret_cast<Show2D*>(m_Depth)->setFullScreen(isFull);
        reinterpret_cast<Show2D*>(m_IR)->setFullScreen(isFull);
    }

    void setCallBackForShow3D(std::function<void(void)> && cb)
    {
        reinterpret_cast<Show3D*>(m_CloudPoint)->setCallBackForVTK(std::forward<std::function<void(void)>>(cb));
    }

    void setCallBackForShow2DDepth(std::function<void(void)> && cb)
    {
        reinterpret_cast<Show2D*>(m_Depth)->setCallBack(std::forward<std::function<void(void)>>(cb));
    }

    void setCallBackForShow2DIR(std::function<void(void)> && cb)
    {
        reinterpret_cast<Show2D*>(m_IR)->setCallBack(std::forward<std::function<void(void)>>(cb));
    }

    void saveData();

    Show3D * getCloudPointShow() { return reinterpret_cast<Show3D*>(m_CloudPoint); }

signals:
    void renderDataSig(int type);


private:
    std::future<void>               m_thread;
    bool                            m_shutDown                  = true;
    BaseWidget *                    m_IR                        = nullptr;
    BaseWidget *                    m_Depth                     = nullptr;
    BaseWidget *                    m_CloudPoint                = nullptr;
    QWidget *                       m_dockIR                    = nullptr;
    QWidget *                       m_dockDepth                 = nullptr;
    QWidget *                       m_dockCloudPoint            = nullptr;
    std::mutex                      m_mutex;
    bool                            m_isLocked                  = false;


};



#endif